//
//  Creator .swift
//  CViews
//
//  Created by xhl_dabaoMac on 2021/11/12.
//

import Foundation
import SnapKit


/// view的创建器
public class Creator{
    
    /// 创建一个居中填充，有点击事件的ImageView
    /// - Parameter image: 本地图片
    /// - Returns: 返回UIImageView
    public static func getImageView(image:UIImage?) -> UIImageView {
        
        let imageView = UIImageView(image: image)
        imageView.isUserInteractionEnabled = true
        imageView.contentMode = .center
        return imageView
    }
    
    /// 创建一个label
    /// - Parameters:
    ///   - title: label的文本
    ///   - font: 字体大小
    ///   - textAlignment: 文字的对齐方式
    ///   - textColor: 文字的颜色
    /// - Returns: 返回UILabel
    public static func getlabel(title:String = "",
                                font:UIFont = UIFont.systemFont(ofSize: 20),
                                textAlignment:NSTextAlignment = .center,
                                textColor : UIColor =  UIColor.black) -> UILabel {
        
        let label = UILabel()
        label.text = title
        label.textAlignment = textAlignment
        label.font = font
        label.textColor = textColor
        return label
    }
    
    /// 创建一个图片，这里可以拦截，便于统一处理图片（例：全局置灰）
    /// - Parameter name: 图片名字
    /// - Returns: UIImage
    public static func getImage(_ name:String = "") -> UIImage? {
        let image = UIImage(named: name)
        return image
    }
    
    /// 批量获取图片
    /// - Parameter names: 图片名字的数组
    /// - Returns: 图片数组
    public static func getImages(_ names:[String]) -> [UIImage?] {
        var images = [UIImage?]()
        for name in names {
            let image = UIImage(named: name)
            images.append(image)
        }
        return images
    }
    
    /// 获取一个切圆角的View
    /// - Parameter cornerRadius: 圆角
    /// - Returns: 圆角的View
    public static func getFilletView(cornerRadius:CGFloat) -> UIView {
        let view = UIView()
        view.layer.masksToBounds = true
        view.layer.cornerRadius = cornerRadius
        return view
    }
    
    /// 获取一个切圆角和阴影的View
    /// - Parameters:
    ///   - cornerRadius: 圆角
    ///   - shadowColor: 阴影颜色
    ///   - shadowOpacity: 阴影宽度
    ///   - shadowOffset: 阴影的偏移
    /// - Returns: 圆角和阴影的View
    public static func getFilletShadowView(cornerRadius:CGFloat,
                                           shadowColor:UIColor = CColor.color(0xE5E5E5),
                                           shadowOpacity:Float = 2,
                                           shadowOffset:CGSize = .zero) -> UIView {
        let view = UIView()
        view.layer.shadowColor = shadowColor.cgColor
        view.layer.shadowOpacity = shadowOpacity
        view.layer.shadowOffset = shadowOffset
        view.layer.cornerRadius = cornerRadius
        return view
    }

    
    /// 创建一个UITextField
    public static func getTextField(placeholder:String = "",
                                    font:UIFont = UIFont.systemFont(ofSize: 20),
                                    textColor : UIColor =  UIColor.black) -> UIView {
        
        let textField = UITextField()
        //留给大师兄实现
        
        
        return textField
    }
    
}
